﻿using Client.Entity;
using Client.IBLL;
using Client.IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Client.BLL {
  public class UserBLL : IUserBLL {
    IUserDAL _userDAL;
    public UserBLL(IUserDAL userDAL) {
      _userDAL = userDAL;
    }
    public async Task<List<UserEntity>> GetAll() {
      string usersStr = await _userDAL.GetAll();
      return Newtonsoft.Json.JsonConvert.DeserializeObject<List<UserEntity>>(usersStr);
    }

    public async Task<List<RoleEntity>> GetRolesByUserId(int userId) {
      var rolesStr = await _userDAL.GetRolesByUserId(userId);
      return Newtonsoft.Json.JsonConvert.DeserializeObject<List<RoleEntity>>(rolesStr);

    }

    public Task ResetPassword(string userId) {
      return _userDAL.ResetPassword(userId);
    }

    public Task SaveUser(UserEntity userEntity) {
      return _userDAL.SaveUser(Newtonsoft.Json.JsonConvert.SerializeObject(userEntity));
    }
  }
}
